package com.yuexunit.finance.project.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.common.util.DateUtils;
import com.yuexunit.finance.project.entity.FinanceCommissionInfoEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.persist.annotation.Transactional;

/**
*@version 创建时间：2016年9月28日 下午3:42:41
*@author wenwenlong
*类说明
*/

@Implements(FinanceCommissionInfoService.class)
public class FinanceCommissionInfoServiceImpl implements FinanceCommissionInfoService {
	@Override
	@Transactional
	public Long createFinanceCommissionInfo(FinanceCommissionInfoEntity entity) {
		entity.setCreateDateTime(DateUtils.now());
		entity.setBillState(Boolean.FALSE);
		PersistUtil.insert(entity);
		return entity.getEnterpriseId();
	}

	@Override
	@Transactional
	public void updateFinanceCommissionInfo(FinanceCommissionInfoEntity entity) {
		PersistUtil.update(entity);
	}

	@Override
	@Transactional
	public void deleteFinanceCommissionInfoEntity(Long financeId) {
		PersistUtil.delete(FinanceCommissionInfoEntity.class, financeId);
	}

	@Override
	public FinanceCommissionInfoEntity inquireFinanceCommissionInfo(Long financeId) {
		return PersistUtil.get(FinanceCommissionInfoEntity.class, financeId);
	}

	@Override
	public PageList<FinanceCommissionInfoEntity> inquireFinanceCommissionInfoPageList(Long extractId, Long enterpriseId, Long accountId, Integer type,
			PageCriteria page) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceCommissionInfoEntity.class);
		if (enterpriseId != null) {
			criteria.add(Restrictions.eq("enterpriseId", enterpriseId));
		}
		if (extractId != null) {
			criteria.add(Restrictions.eq("extractId", extractId));
		}
		if (accountId != null) {
			criteria.add(Restrictions.eq("accountId", accountId));
		}
		if (type != null) {
			criteria.add(Restrictions.eq("type", type));
		}
		criteria.addOrder(Order.desc("createDateTime"));
		return PersistUtil.get(criteria, page);
	}

	@Override
	public List<FinanceCommissionInfoEntity> inquireFinanceCommissionInfoList(Long extractId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceCommissionInfoEntity.class);
		if (extractId != null) {
			criteria.add(Restrictions.eq("extractId", extractId));
		}
		return PersistUtil.get(criteria);
	}
}
